package com.ruoyi.insurance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.insurance.domain.Defend;
import com.ruoyi.insurance.service.IDefendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 防护Controller
 * 
 * @author ruoyi
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/insurance/defend")
public class DefendController extends BaseController
{
    @Autowired
    private IDefendService defendService;

    /**
     * 查询防护列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:defend:list')")
    @GetMapping("/list")
    public TableDataInfo list(Defend defend)
    {
        startPage();
        List<Defend> list = defendService.selectDefendList(defend);
        return getDataTable(list);
    }

    /**
     * 导出防护列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:defend:export')")
    @Log(title = "防护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Defend defend)
    {
        List<Defend> list = defendService.selectDefendList(defend);
        ExcelUtil<Defend> util = new ExcelUtil<Defend>(Defend.class);
        util.exportExcel(response, list, "防护数据");
    }

    /**
     * 获取防护详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:defend:query')")
    @GetMapping(value = "/{defendId}")
    public AjaxResult getInfo(@PathVariable("defendId") Long defendId)
    {
        return success(defendService.selectDefendByDefendId(defendId));
    }

    /**
     * 新增防护
     */
    @PreAuthorize("@ss.hasPermi('insurance:defend:add')")
    @Log(title = "防护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Defend defend)
    {
        return toAjax(defendService.insertDefend(defend));
    }

    /**
     * 修改防护
     */
    @PreAuthorize("@ss.hasPermi('insurance:defend:edit')")
    @Log(title = "防护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Defend defend)
    {
        return toAjax(defendService.updateDefend(defend));
    }

    /**
     * 删除防护
     */
    @PreAuthorize("@ss.hasPermi('insurance:defend:remove')")
    @Log(title = "防护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{defendIds}")
    public AjaxResult remove(@PathVariable Long[] defendIds)
    {
        return toAjax(defendService.deleteDefendByDefendIds(defendIds));
    }
}
